<template>
	<xn-form-container
		:title="formData.id ? '编辑互助金订单信息' : '增加互助金订单信息'"
		:width="700"
		v-model:open="open"
		:destroy-on-close="true"
		@close="onClose"
	>
		<a-form v-show="formData.id" ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-form-item label="商户订单号：" name="outTradeNo">
				<a-input v-model:value="formData.outTradeNo" placeholder="请输入商户订单号" allow-clear />
			</a-form-item>
			<a-form-item label="缴纳金额：" name="totalFee">
				<a-input v-model:value="formData.totalFee" placeholder="请输入订单金额" allow-clear />
			</a-form-item>
			<a-form-item label="缴纳人员姓名" name="userId">
				<a-input v-model:value="formData.userId" placeholder="请输入订单关联用户的ID" allow-clear />
			</a-form-item>
			<a-form-item label="缴纳人员电话：" name="userrPhone">
				<a-input v-model:value="formData.userrPhone" placeholder="请输入用户电话" allow-clear />
			</a-form-item>
			<a-form-item label="用户关联企业微信ID：" name="userOpenId">
				<a-input v-model:value="formData.userOpenId" placeholder="请输入用户关联企业微信ID" allow-clear />
			</a-form-item>
			<a-form-item label="订单状态：" name="orderStatus">
				<a-input v-model:value="formData.orderStatus" placeholder="请输入订单状态" allow-clear />
			</a-form-item>
			<a-form-item label="订单类型：" name="orderType">
				<a-input v-model:value="formData.orderType" placeholder="请输入订单类型" allow-clear />
			</a-form-item>
			<a-form-item label="付款渠道：" name="bankType">
				<a-input v-model:value="formData.bankType" placeholder="请输入付款渠道" allow-clear />
			</a-form-item>
		</a-form>
		<div v-show="!formData.id">占位显示订单二维码</div>

		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
			<a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
		</template>
	</xn-form-container>
</template>

<script setup name="bizPayOrderForm">
import { cloneDeep } from 'lodash-es'
import { required } from '@/utils/formRules'
import bizPayOrderApi from '@/api/biz/bizPayOrderApi'
// 抽屉状态
const open = ref(false)
const emit = defineEmits({ successful: null })
const formRef = ref()
// 表单数据
const formData = ref({})
const submitLoading = ref(false)

// 打开抽屉
const onOpen = (record) => {
	open.value = true
	if (record) {
		let recordData = cloneDeep(record)
		formData.value = Object.assign({}, recordData)
	}
}
// 关闭抽屉
const onClose = () => {
	formRef.value.resetFields()
	formData.value = {}
	open.value = false
}
// 默认要校验的
const formRules = {}
// 验证并提交数据
const onSubmit = () => {
	formRef.value
		.validate()
		.then(() => {
			submitLoading.value = true
			const formDataParam = cloneDeep(formData.value)
			bizPayOrderApi
				.bizPayOrderSubmitForm(formDataParam, formDataParam.id)
				.then(() => {
					onClose()
					emit('successful')
				})
				.finally(() => {
					submitLoading.value = false
				})
		})
		.catch(() => {})
}
// 抛出函数
defineExpose({
	onOpen
})
</script>
